package com.fdb.efp.esb.service.impl.sed.pls;

import java.util.List;
import java.util.Optional;

import com.fdb.efp.esb.common.client.resp.EsbRespRetInfBean;
import com.fdb.efp.esb.common.client.resp.EsbRespServiceBean;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSONObject;
import com.fdb.basic.framework.core.constant.ESBConstant;
import com.fdb.basic.framework.core.exception.ESBException;
import com.fdb.efp.esb.service.bo.req.sed.pls.ReqModifyTellerPassBean;
import com.fdb.efp.esb.service.client.ESBClientFactory;
import com.fdb.efp.esb.service.facade.sed.pls.ModifyTellerPassService;

/**
 * 需求编号：2019D0519<br/>
 * 问题编号：<br/>
 * 功能描述：柜员密码修改同步服务实现类<br/>
 * 开发人员：周才顺<br/>
 * 创建日期：2019年6月17日 上午9:11:44
 * @author zhoucs1
 * @since  1.0
 * @version 1.0
 */
@Service("modifyTellerPassService")
public class ModifyTellerPassServiceImpl implements ModifyTellerPassService{

	//日志记录器
	private static Logger logger = LoggerFactory.getLogger(ModifyTellerPassServiceImpl.class);
	
	@Override
	public void modifyPass(ReqModifyTellerPassBean reqModifyTellerPassBean) throws Exception{
		logger.debug("正在调用柜员密码修改同步接口，请求参数：" + JSONObject.toJSONString(reqModifyTellerPassBean));
		try {
			EsbRespServiceBean esbRespServiceBean = ESBClientFactory.buildClient().withBody(reqModifyTellerPassBean)
					.withTradeNo(ESBConstant.SYSTEM_ID_GAPS).withScene(ESBConstant.SCENE_NO_04).create()
					.sendAndReceive();
			Optional.ofNullable(esbRespServiceBean.getSysHead()).orElseThrow(()->new ESBException("访问ESB发生异常，请检查请求参数是否正确或ESB是否连通"));
			List<EsbRespRetInfBean> retInfArry = esbRespServiceBean.getSysHead().getRetInfArry();
			
			if(!"000000".equals(retInfArry.get(0).getRetCd())) {
				throw new  ESBException("大前置系统发生异常，返回信息为" + retInfArry.toString());
			}
			
			logger.info("调用柜员密码修改同步接口结束");
		} catch (ESBException e) {
			logger.error("调用柜员密码修改同步接口出现异常：" + e.getMessage());
			throw new ESBException("调用柜员密码修改同步接口出现异常：" + e.getMessage());
		}
	}

}
